import { AdManager } from "../ads/AdManager";
import { AdManager_KS } from "../ads/AdManager_KS";
import { AdManager_WX } from "../ads/AdManager_WX";
import { AdManager_ZJ } from "../ads/AdManager_ZJ";
import { BUNDLE_TYPE_ENUM, EVENT_NAME_ENUM, GAME_TYPE_ENUM, RELEASE_TYPE_ENUM } from "../base/EnumIndex";
import { TimeTools } from "../common/TimeTools";
import { Tools } from "../common/Tools";
import { AudioManager } from "../manager/AudioManager";
import { EventManager } from "../manager/EventManager";
import { LevelManager } from "../manager/LevelManager";
import { UIManager } from "../manager/UIManager";
import HomeUI from "./HomeUI";
const tt = window['tt'];
const { ccclass, property } = cc._decorator;

@ccclass
export default class ShopUI extends cc.Component {


    start() {
        this.node.getChildByName("mask").on("click", () => {
            this.clickBtnClose();
        });
    }



    clickBtnClose() {
        AudioManager.playClick();
        UIManager.ins.close();
    }

    clickBuyItem(event, data) {
        data = JSON.parse(data);
        AudioManager.playClick();
        let gold = parseFloat(Tools.getStorage("gold", true)) ? parseFloat(Tools.getStorage("gold", true)) : 0;
        console.log(data);

        if (gold - data.cost >= 0) {
            HomeUI.goldUpData(gold - data.cost);
            let baofuzhi = Number(Tools.getStorage("饱腹值"));
            baofuzhi += data.baoshi;
            console.log("增加后饱腹值", baofuzhi);

            if (baofuzhi >= 100) {
                baofuzhi = 100
            }
            Tools.setStorage("饱腹值", baofuzhi);
            EventManager.ins.emit(EVENT_NAME_ENUM.UPDATE_HOME_COST);
            UIManager.ins.showToast("购买成功");

            AudioManager.playAudio("吃肉",1,BUNDLE_TYPE_ENUM.HOME);
        } else {
            UIManager.ins.showToast("金币不足前往通关获取");
            HomeUI.goldUpData(gold)
        }

    }

    clickGuanggaoItem() {
        AudioManager.playClick();
        AdManager.naoLiReportVideo(2, "饱腹值加满");
        UIManager.ins.enabledClick(false);
        AdManager.showVideoAd(() => {
            UIManager.ins.enabledClick(true);
            AdManager.naoLiReportVideo(3, "饱腹值加满");
            AdManager.naoLiReportVideo(4, "饱腹值加满");
            let baofuzhi = Number(Tools.getStorage("饱腹值"));
            baofuzhi += 100;
            console.log("增加后饱腹值", baofuzhi);

            if (baofuzhi >= 100) {
                baofuzhi = 100
            }
            Tools.setStorage("饱腹值", baofuzhi);
            EventManager.ins.emit(EVENT_NAME_ENUM.UPDATE_HOME_COST);

            AudioManager.playAudio("吃肉",1,BUNDLE_TYPE_ENUM.HOME);
        }, () => {
            UIManager.ins.enabledClick(true);
        });

    }
    // update (dt) {}
}
